package com.lu.controller;

import com.lu.bean.AppException;
import com.lu.bean.ResBean;
import com.lu.constant.ErrorEnum;
import com.lu.constant.TypeEnum;
import com.lu.dao.po.WgSubmitRecord;
import com.lu.service.SubmitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 游戏提交类
 * @author luke
 * @className SubmitController
 * @date 2021/07/13 11:47
 */
@Slf4j
@RestController
@Api(tags = "游戏提交类")
public class SubmitController {

    @Resource
    private SubmitService submitService;

    /**
     * 用户提交图画
     * @author luke
     * @date 2021/7/13 14:31
     * @param branchId 游戏支线id
     * @param openId 玩家openid
     * @param userName 玩家昵称
     * @param picture 图片id
     * @return com.lu.bean.ResBean
     */
    @RequestMapping(value = "/submit/submitPicture", method = RequestMethod.POST)
    @ApiOperation("用户提交图画")
    public ResBean submitPicture(@ApiParam(value = "游戏支线id", required = true) @RequestParam String branchId,
                                 @ApiParam(value = "玩家openid", required = true) @RequestParam String openId,
                                 @ApiParam(value = "玩家昵称", required = true) @RequestParam String userName,
                                 @ApiParam(value = "图片id", required = true) @RequestParam String picture) {
        ResBean res = new ResBean();
        try {
            WgSubmitRecord bean = new WgSubmitRecord();
            bean.setBranchId(branchId);
            bean.setOpenId(openId);
            bean.setUserName(userName);
            bean.setPicture(picture);
            bean.setType(TypeEnum.PICTURE.code);
            submitService.submit(bean);
        } catch (AppException e) {
            log.error("AppException occur,{},",e.toString(),e);
            res.setByAppException(e);
        } catch (Exception e) {
            log.error("Exception occur,",e);
            res.setResCode(ErrorEnum.FAIL.code);
            res.setResMsg("服务器异常");
        }
        return res;
    }

    /**
     * 用户提交猜词
     * @author luke
     * @date 2021/7/13 15:03
     * @param branchId
     * @param openId
     * @param userName
     * @param word
     * @return com.lu.bean.ResBean
     */
    @RequestMapping(value = "/submit/submitWord", method = RequestMethod.POST)
    @ApiOperation("用户提交猜词")
    public ResBean submitWord(@ApiParam(value = "游戏支线id", required = true) @RequestParam String branchId,
                              @ApiParam(value = "玩家openid", required = true) @RequestParam String openId,
                              @ApiParam(value = "玩家昵称", required = true) @RequestParam String userName,
                              @ApiParam(value = "玩家猜词", required = true) @RequestParam String word) {
        ResBean res = new ResBean();
        try {
            WgSubmitRecord bean = new WgSubmitRecord();
            bean.setBranchId(branchId);
            bean.setOpenId(openId);
            bean.setUserName(userName);
            bean.setGuessWord(word);
            bean.setType(TypeEnum.WORD.code);
            submitService.submit(bean);
        } catch (AppException e) {
            log.error("AppException occur,{},",e.toString(),e);
            res.setByAppException(e);
        } catch (Exception e) {
            log.error("Exception occur,",e);
            res.setResCode(ErrorEnum.FAIL.code);
            res.setResMsg("服务器异常");
        }
        return res;
    }


}
